package com.sccc.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sccc.Converter.AdminConverter;
import com.sccc.biz.IadminManeger;
import com.sccc.bizImpl.AdminManeger;
import com.sccc.bizImpl.UserManeger;
import com.sccc.entity.Admin;
import com.sccc.entity.User;

public class AdminAction extends ActionSupport {
  
private Admin adminInfo;
private List<User> users;
private int UserNumberAll;

public int getUserNumberAll() {
	return UserNumberAll;
}

public void setUserNumberAll(int userNumberAll) {
	UserNumberAll = userNumberAll;
}



ActionContext ctx = ActionContext.getContext();//获取ActionContext对象
HttpServletRequest request = ServletActionContext.getRequest();  //获取request对象
AdminManeger adminmaneger = new AdminManeger();//所有方法的一个对象



	public Admin getAdminInfo() {
	return adminInfo;
}

public void setAdminInfo(Admin adminInfo) {
	this.adminInfo = adminInfo;
}

public List<User> getUsers() {
	return users;
}

public void setUsers(List<User> users) {
	this.users = users;
}

	public String login() throws Exception {
//		System.out.println(adminInfo);
//		System.out.println(adminInfo.getUsername());
//		System.out.println(adminInfo.getPasswd());
		//判断管理员用户名
	
		Admin user = new Admin();
		user.setUsername(adminInfo.getUsername());
		user.setPasswd(adminInfo.getPasswd());
		
		
		if(adminmaneger.Userlogin(user)){
			users = adminmaneger.All();//返回所有用户信息
			ctx.getSession().put("adminName", adminInfo.getUsername()); //存管理员用户名
			ctx.getSession().put("allUser", users); //存所有用户集合
			ctx.getSession().put("AdminName",user.getName()); //存管理员名字
			int UserNumberAll = adminmaneger.SQLall();//会员总人数 

			ctx.getSession().put("UserNumber",UserNumberAll); //会员总人数 
			return SUCCESS;
		}
		
		
		return ERROR;
	
	}
//	
//	public String findone(int id) throws Exception {
//		if(adminmaneger.findOneAll(id)!=null){
//			
//		
//		User user = adminmaneger.findOneAll(id);
//		
//		request.setAttribute("Username", user.getUsername());
//		request.setAttribute("Userpasswd", user.getPasswd());
//		request.setAttribute("Usersex", user.getSex());
//		request.setAttribute("Userjob", user.getJob());
//		request.setAttribute("Useremail", user.getEmail());
//		return "ShowfindOneAll";
//		
//		}
//		return ERROR;
//		
//	}
	


	public String go() throws Exception {
		
		return "go";
	}

}
